package com.sudoku.solver;

import com.sudoku.board.Board;
import com.sudoku.board.Box;
import com.sudoku.board.Tile;

public class SolePencilCandidate extends Strategy{

	public SolePencilCandidate(Solver solver) {
		super(solver);
	}

	@Override
	public boolean solve(Board board) {
		stuck=true;
		for (Box box : board.getData()) {
			for (Tile tile : box.getData()) {
				if (solePencilCandidate(tile)) {
					stuck = false;
				}
			}
		}
		return stuck;
	}
	
	/**
	 * Check for only 1 penciled number in a tile
	 * 
	 * @param tile
	 * @return if change to tile was made
	 */
	private boolean solePencilCandidate(Tile tile) {
		if (tile.isBlank()) {
			// check for 1 pencil number in tile
			if (tile.getPencilNumbers().size() == 1) {
				solver.setNewTileData(tile, Board.IntToChar(tile.getPencilNumbers().get(0)));
				return true;
			}
		}
		return false;
	}

}
